import { createParamDecorator } from '@nestjs/common'
import { getIp } from '@/utils/ip'

import type { ExecutionContext } from '@nestjs/common'
import type { Request } from 'express'

/**
 * 快速获取IP
 */
export const Ip = createParamDecorator((_, context: ExecutionContext) => {
	const request = context.switchToHttp().getRequest<Request>()
	return getIp(request)
})

/**
 * 快速获取request path，并不包括url params
 */
export const Uri = createParamDecorator((_, context: ExecutionContext) => {
	const request = context.switchToHttp().getRequest<Request>()
	return request.url
})
